<script>
function parseResult(response)
{
	var data = jQuery.parseJSON(response);
	if (data.code==true)
	{
		$('#step2panel').fadeIn();
	}
	$("#databaseresult").html(data.html);
}

$(document).ready(function() {
$('#databasefrm input').keypress(function() {
if ($('#database').val()!="")
	$('#step3').attr('disabled','disabled')
else	
	$('#step3').removeAttr('disabled');

	
if( $('#step2panel').is(':visible') ) {
    // it's visible, do something
			$('#step2panel').fadeOut();
			$("#databaseresult").html("");
			$("#databaseresultstep2").html("");
			$("#databaseresultstep3").html("");
			$("#databaseresultstep4").html("");
			
}

  });
});

</script>
<div id="tmpinformation" style="margin-left:10px;margin-right:10px">
<fieldset>
<legend>Prerequisites :</legend>
<?php
//echo $tmpmessage;
echo $this->element('message');
?>
</fieldset>
</div>
<div id="databasepanel" style="margin-top: 10px;margin-left:10px;margin-right:10px">
<?php
echo $form->create(null,array('action'=>'index','id'=>'databasefrm'));
?>
<fieldset>
<legend>Step 1 - Database configuration :</legend>
<?php
echo "<p>".$form->input('host',array('class'=>'required','div'=>false,'label'=>'Server host :'))."<em>*</em></p>";
echo "<p>".$form->input('login',array('class'=>'required','div'=>false,'label'=>'Root username :'))."<em>*</em></p>";
echo "<p>".$form->input('password',array('type'=>'password','div'=>false,'label'=>'Root password :'))."</p>";
echo "<p>".$form->input('database',array('div'=>false,'id'=>'database','label'=>'Database (leave blank if you want to create it) :'))."</p>";
echo "<p>".$form->input('prefix',array('div'=>false,'label'=>'Prefix for tables (if needed) :'))."</p>";
echo "<p></p><center>".$js->submit('Check config',array('success'=>'parseResult(data);','div'=>false,'url'=>array('action'=>'checkConnection'),null))."<div id='databaseresult' style='display:inline;margin-left:10px'></div></center>";
?>
</fieldset>
</div>

<div id="step2panel" style="margin-top:10px;margin-left:10px;margin-right:10px;display:none">
<fieldset>
<legend>Step 2 - Creation :</legend>
<p></p><center>
<input type="submit" value="Create config file (mandatory)" id="step2">
<?php
$this->Js->get('#step2');
$this->Js->event('click', 
	$js->request(array('action'=>'createconfigfile'),array('success'=>'$("#step3").fadeIn();$("#step4").fadeIn();$("#step5").fadeIn();','update'=>'#databaseresultstep2','div'=>false,null))
);
?>
<div id='databaseresultstep2' style='display:inline;margin-left:10px'></div>
<input type="submit" value="1 - Create Database" id="step3" style="display:none">
<?php
$this->Js->get('#step3');
$this->Js->event('click', 
	$js->request(array('action'=>'createdatabase'),array('update'=>'#databaseresultstep3','div'=>false,null))
);
?>
<div id='databaseresultstep3' style='display:inline;margin-left:10px'></div>
<input type="submit" value="2 - Create tables" id="step4" style="display:none">
<?php
$this->Js->get('#step4');
$this->Js->event('click', 
	$js->request(array('action'=>'createtable'),array('update'=>'#databaseresultstep4','div'=>false,null))
);
?>
<div id='databaseresultstep4' style='display:inline;margin-left:10px'></div>
<input type="submit" value="3 - Create data" id="step5" style="display:none">
<?php
$this->Js->get('#step5');
$this->Js->event('click', 
	$js->request(array('action'=>'createdata'),array('success'=>'$("#step3panel").fadeIn();','update'=>'#databaseresultstep5','div'=>false,null))
);
?>
<div id='databaseresultstep5' style='display:inline;margin-left:10px'></div>

</center>
</fieldset>
</div>

<div id="step3panel" style="margin-top:10px;margin-left:10px;margin-right:10px;display:none">
<fieldset>
<legend>Step 3 - Install complete!</legend>
<p></p><center>
The install is now complete.
If you have some errors, please contact me.<br/>
You can login in the <a href="/" style="font-size: 1em;font-weight: bold;">main interface</a> and you <b><u>must</u></b> configure Bukkit Webadmin now.<br/>
The default login/password is admin/admin.
</center>
</fieldset>
</div>

<?php echo $this->Js->writeBuffer(); ?>
